﻿CREATE TABLE [CO].[LedgerAccounts] (
    [Id]            INT           NOT NULL,
    [ParentId]      INT           NULL,
    [AccountNumber] VARCHAR (50)  NOT NULL,
    [Name]          VARCHAR (100) NOT NULL,
    [Note]          VARCHAR (250) NULL,
    [MD]            DATETIME      CONSTRAINT [DF__LedgerAccoun__MD__6AC5C326] DEFAULT (getdate()) NOT NULL,
    [MW]            VARCHAR (50)  CONSTRAINT [DF__LedgerAccoun__MW__6BB9E75F] DEFAULT (suser_sname()) NOT NULL,
    [ToDelete]      BIT           DEFAULT ((0)) NOT NULL,
    CONSTRAINT [PK_LedgerAccounts] PRIMARY KEY CLUSTERED ([Id] ASC),
    CONSTRAINT [FK_LedgerAccounts_LedgerAccounts] FOREIGN KEY ([ParentId]) REFERENCES [CO].[LedgerAccounts] ([Id]) NOT FOR REPLICATION
);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Для субсчета ссылка на родительский счет', @level0type = N'SCHEMA', @level0name = N'CO', @level1type = N'TABLE', @level1name = N'LedgerAccounts', @level2type = N'COLUMN', @level2name = N'ParentId';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Номер счета', @level0type = N'SCHEMA', @level0name = N'CO', @level1type = N'TABLE', @level1name = N'LedgerAccounts', @level2type = N'COLUMN', @level2name = N'AccountNumber';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Признак того, что запись нужно удалить из БД всех подразделений', @level0type = N'SCHEMA', @level0name = N'CO', @level1type = N'TABLE', @level1name = N'LedgerAccounts', @level2type = N'COLUMN', @level2name = N'ToDelete';

